package coc

import (
	"fmt"
	"regexp"
	"strings"
	"trpg-common/logger"
	"trpg-message/commands/trpg"
	"trpg-message/entity"
)

type Cocrc struct {
}

func (cocrc Cocrc) Handle(message entity.Message, argStr string) string {
	split := strings.Split(argStr, " ")
	if len(split) != 1 {
		return fmt.Sprintf("参数错误")
	}
	re := regexp.MustCompile("[a-zA-Z\u4e00-\u9fa5]{2,10}")
	if !re.MatchString(split[0]) {
		return "错误的参数，请重新输入~"
	}
	arg := re.FindString(split[0])
	attributes := roomDao.GetRoomBindCharacter(message.RoomId, message.Creator)
	if attributes == nil {
		return "没有设定调查员参数~"
	}
	logger.Logger.Info(arg)
	attribute, ok := attributes[arg]
	if ok == false {
		return "没有设置这项属性"
	} else {
		checkResult, rand := trpg.GetCheckResult(attribute, message.RoomId)
		result := fmt.Sprintf("「%v」进行「%v」检定：1d100=%v/%v，", message.CreatorName, arg, rand, attribute)
		switch checkResult {
		case 0:
			result += "大成功！「祂盯上你了」"
			break
		case 1:
			result += "极难成功！「幸运女神在微笑」"
			break
		case 2:
			result += "困难成功！「超常发挥」"
			break
		case 3:
			result += "成功！「侥幸而已」"
			break
		case 4:
			result += "失败！「不要相信概率，专家也会失手」"
			break
		case 5:
			result += "大失败！「深渊在看着你！」"
			break
		}
		return result
	}
}
